<template>
	<view class="login">
		<view class="title">
			<view>重新设置密码</view>
			<view>请输入至少6位数字与字母组合的新密码</view>
		</view>
		
		<view class="form">
			<view>
				<input type="text" v-model="form.mobile" placeholder="请输入手机号"/>
			</view>
			<view>
				<input type="text" v-model="form.yzm" placeholder="请输入验证码"/>
				<text  @click="C_getCode">{{getCodeText}}</text>
			</view>
			<view>
				<input type="text" v-model="form.pass" placeholder="请输入密码"/>
			</view>
		</view>
		
		<view class="submit" @click="C_submit">确定修改</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				getCodeText:'获取验证码',
				form:{
					mobile:'',
					yzm:'',
					pass:''
				}
			};
		},
		methods:{
			async C_getCode(){
				let {mobile} = this.form
				if(!this.$u.utils.yz.isMobile(mobile)){this.$u.toast('请输入正确的手机号');return}
				if(this.getCodeText == '获取验证码'){
					this.$u.utils.getCode(this)
					let smsCode = await this.$u.api.send_msg({mobile})
					console.log(smsCode,'smsCode');
					
				}
			},
			async C_submit(){
				let {mobile,yzm,pass} = this.form
				if(!this.$u.utils.yz.isMobile(mobile)){this.$u.toast('请输入正确的手机号');return}
				if(!yzm){this.$u.toast('请输入验证码');return}
				if(!pass){this.$u.toast('请输入密码');return}
				let params = {mobile,msg:yzm,password:pass}
				let edit_pass = await this.$u.api.edit_pass(params)
				console.log(edit_pass);
				if(edit_pass.code == 0){
					this.$u.toast('修改成功')
					setTimeout(_=>{
						uni.navigateBack()
					},700)
				}else{
					this.$u.toast(edit_pass.msg)
				}
				
				
				// if(edit_pass.code == 0){
					// uni.reLaunch({
					// 	url:'/pages/healthy/healthy'
					// })
				// }
			}
		}
	}
</script>

<style lang="scss">
	@import "../loginCommon.scss";
</style>
